# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=spreed-webrtc
pkgver=0.29.7
pkgrel=3
pkgdesc="WebRTC audio/video call and conferencing server"
url="http://spreed.me"
arch="all !mips !mips64" # blocked by nodejs
license="AGPL-3.0"
makedepends="autoconf automake go go-context go-acceptlanguageparser
	go-conf go-httputils go-mux go-nats go-nuid go-pkac go-phoenix
	go-securecookie go-sloth go-spreed-turnservicecli go-uuid go-websocket
	nodejs"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
pkgusers="spreed"
pkggroups="spreed"
_vendor="strukturag"
source="$pkgname-$pkgver.tar.gz::https://github.com/$_vendor/spreed-webrtc/archive/v$pkgver.tar.gz
	$pkgname.initd"
builddir="$srcdir"/$pkgname-$pkgver

prepare() {
	cd "$builddir"
	./autogen.sh
	#some libraries aren't in the expected path in the tarball
	mkdir -p src/github.com/$_vendor/$pkgname && mv go src/github.com/$_vendor/$pkgname
	#fix default server config
	sed -i 's|;root = /usr/share/spreed-webrtc-server/www|root = /usr/share/spreed-webrtc-server/www|' \
		server.conf.in
}

build() {
	cd "$builddir"
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make GOPATH="$GOPATH $builddir/go:$builddir/src" assets
	make GOPATH="$GOPATH $builddir:$builddir/go:$builddir/src" binaryall
}

check() {
	cd "$builddir"
	make test
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	mv doc/* "$pkgdir"/usr/share/doc/$pkgname
	install -m644 -D server.conf.in "$pkgdir"/etc/$pkgname/${pkgname}-server.conf
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/${pkgname}-server
}

sha512sums="bc4acf1dc53325c4da19429a802fdba8d72e619dbf7e872d007b87fbc711e9e63962a83c770f77d44c2454bc038bef0306d57556e86381d4e4c48262030af30b  spreed-webrtc-0.29.7.tar.gz
1419b5cbec88f18de71d5dc550bde3d784fc744f0675115ad57e55ebbdbc9f65222584f806bfd6ed2a9b3d4e1c14fe92d8f220cd105851abcb4f4956a6cf6e3a  spreed-webrtc.initd"
